<?php


namespace app\admin\controller;


use think\captcha\Captcha;
use think\Controller;

class Login extends Controller
{
    private $admin;


    public function index(){
        if(request()->isPost()){
            $this->check(input('code'));
            $data = input('post.');
            $this->admin = new \app\admin\model\Admin();
            $res = $this->admin->login($data);
            if($res===1){
                $this->error("用户名不存在",url('index'));
            }else if($res===2){
                $this->success("信息正确，正在登陆",url('index/index'));
            }else{
                $this->error("密码错误",url('index'));
            }
            return;
        }
        return view('login');
    }

    //验证码检测
    public function check($code=''){
        $captcha = new Captcha();
        if(!$captcha->check($code)){
            $this->error('验证码错误');
        }else{
            return true;
        }

//        if(!captcha_check($code)){
//            $this->error('验证码错误');
//        }else{
//           return true;
//        }
    }
}